package com.card.server;

import java.util.List;

import javax.jdo.PersistenceManager;

import com.card.client.entry.InputAccounts;
import com.card.client.service.InputAccountsService;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;

@SuppressWarnings("unchecked")
public class InputAccountsImpl extends RemoteServiceServlet implements
		InputAccountsService {

	private static final long serialVersionUID = 3467609027034946019L;

	@Override
	public void addInputAccounts(InputAccounts inputAccounts) {
		PersistenceManager pm = PMF.get().getPersistenceManager();
		if(inputAccounts != null){
			pm.makePersistent(inputAccounts);
		}
		pm.close();
	}

	@Override
	public void delInputAccounts(Long id) {
		PersistenceManager pm = PMF.get().getPersistenceManager();
		if(id != null){
			String query = "select from " + InputAccounts.class.getName() + " where id == " + id;
			List<InputAccounts> result = (List<InputAccounts>)pm.newQuery(query).execute();
			InputAccounts ia = result.get(0);
			pm.deletePersistent(ia);
		}
		pm.close();
	}

	@Override
	public InputAccounts[] getAllInputAccounts() {
		InputAccounts[] result = null;
		PersistenceManager pm = PMF.get().getPersistenceManager();
		List<InputAccounts> list = (List<InputAccounts>)pm.newQuery(InputAccounts.class).execute();
		if(list != null){
			result = new InputAccounts[list.size()];
			for(int i=0;i<result.length;i++){
				result[i] = list.get(i);
			}
		} else {
			result = new InputAccounts[0];
		}
		return result;
	}

	@Override
	public void updateInputAccounts(InputAccounts inputAccounts) {
		PersistenceManager pm = PMF.get().getPersistenceManager();
		if(inputAccounts != null){
			pm.makePersistent(inputAccounts);
		}
		pm.close();
	}

}
